package com.sun.job;

import com.sun.entity.EnhanceUserInfo;
import com.sun.service.UserInfoService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Slf4j
@Component
public class MyXxlJob {

    @Autowired
    private UserInfoService userService;

    @XxlJob(value = "inserUserInfoJob")
    public void inserUserInfo(){
        XxlJobHelper.log("XXL-JOB,userJobHandler start.....");
        log.info("当前执行的JobId:[" + XxlJobHelper.getJobId() + "]");
        for (int i = 0; i < 4; i++) {
            EnhanceUserInfo userInfo = new EnhanceUserInfo();
            userInfo.setUserName(UUID.randomUUID().toString().substring(0,6)).setUserAddress(UUID.randomUUID().toString().substring(0,3))
                    .setUserEmail("234412421@qq.com").setUserStatus("0");
            userService.save(userInfo);
        }
        XxlJobHelper.log("XXL-JOB,userJobHandler end.....");

    }
}
